﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DataAccess.DataObject;
using DataAccess.BusinessObject;
using System.Collections.Generic;

namespace EnmineKaitlin.admin
{
    public partial class email_subcrible : Common.PageBase
    {
        OEmail _OEmail = new OEmail();
        BEmail _BEmail = new BEmail();
        const string module = "manage-user";
        int pagesize = 30;
        int currentpage = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (CheckPermission(module))
            {
                if (!IsPostBack)
                {
                    GetParam();
                    BindEmail();
                }
            }
            else
            {
                Response.Redirect("~/admin/permission-fail.aspx");
            }
        }
        protected void GetParam()
        {
            if (Request["curentpage"] != null && Request["curentpage"].ToString() != "")
            {
                currentpage = int.Parse(Request["currentpage"].ToString());
            }
        }
        protected void BindEmail()
        {
            IList<OEmail> lstEmail = _BEmail.Get(currentpage, pagesize);
            grvEmail.DataSource = lstEmail;
            grvEmail.DataBind();
            if (lstEmail.Count > 0)
            {
                ctlPagging.PageSize = pagesize;
                ctlPagging.ItemCount = (int)lstEmail[0].TotalResult;
                ctlPagging.QueryStringParameterName = "";
                ctlPagging.CurrentIndex = currentpage;
            }
        }
        protected void btnAddEmail_Click(object sender, EventArgs e)
        {
            if (_BEmail.Add(txtEmail.Text))
            {
                txtEmail.Text = "";
                BindEmail();
            }
        }
        protected void grvEmail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            BoundFunctionGridview(e);
        }
        protected void grvEmail_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                if (_BEmail.Delete(e.CommandArgument.ToString()))
                {
                    BindEmail();
                }
                else
                {
                    RegisterClientScriptBlock("NOTE", "<script>alert('Xảy ra lỗi trong quá trình xóa, vui lòng thử lại !');</script>");
                }
            }
        }

        protected void grvEmail_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }
    }
}
